const Router = require('koa-router')
const router = new Router({ prefix: '/user' })
const {
        userLogin, 
        userLoginCookie,
        userLogoutCookie,
        userRegister,
        userInfo, 
        changePassword
    } = require('../controller/user.controller')
const { userValidator, verifyUser, cryptPassword, verifyLogin } = require('../middleware/user.middleware')
const { auth } = require('../middleware/auth.middleware')

// 登录路由(jwt)
router.post('/login', userValidator, verifyLogin, userLogin)
// 登录路由(cookie)
router.get('/loginCookie', userLoginCookie)
// 注销登录(cookie)
router.get('/logoutCookie', userLogoutCookie)
// 注册路由
router.post('/register',userValidator, verifyUser, cryptPassword, userRegister)
// 修改密码
router.patch('/changePassword', auth, cryptPassword, changePassword)
// 获取用户信息路由
router.post('/getUserInfo', userInfo)
// 测试接口
router.get('/test', (ctx) => {
    ctx.body = '接口调用成功!!!'
    console.log('接口调用成功!!!')
})
// 测试 cookie 使用的接口
router.get('/testCookie', (ctx) => {
    // ctx.cookies.set('name', 'jianghaotian')
    ctx.body = 'testCookie接口调用成功'
})


module.exports = router